package com.chookss.login;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.chookss.R;
import com.chookss.tools.MyToast;
import com.chookss.tools.Utils;
import com.chookss.view.VerifyCodeView;
import com.johnrambo.ktea.common.klogutil.KLog;
import com.lvgroup.hospital.base.BaseAct;

import org.jetbrains.annotations.Nullable;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AuthCodeAcquireActivity extends BaseAct {

    @BindView(R.id.verify_code_view)
    VerifyCodeView verifyCodeView;
    private String name, phone;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_auth_code_acquire);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        initState();
        name = getIntent().getStringExtra("name");
        phone = getIntent().getStringExtra("phone");

        verifyCodeView.setInputCompleteListener(new VerifyCodeView.InputCompleteListener() {
            @Override
            public void inputComplete() {
                KLog.i(verifyCodeView.getEditContent());
            }

            @Override
            public void invalidContent() {

            }
        });
    }

    @OnClick({R.id.layoutTop, R.id.tvSure})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.layoutTop:
                finish();
                break;
            case R.id.tvSure:
                if (verifyCodeView == null) {
                    return;
                }
                if (Utils.isNull((verifyCodeView.getEditContent()))) {
                    MyToast.show("验证码不能为空");
                    return;
                }
                if (verifyCodeView.getEditContent().length() == 6) {
                    Intent intent = new Intent(this, SetNewPasswordActivity.class);
                    intent.putExtra("name", name);
                    intent.putExtra("phone", phone);
                    intent.putExtra("authcode", verifyCodeView.getEditContent());
                    startActivity(intent);
                    finish();
                } else {
                    MyToast.show("请正确输入6位验证码");
                }
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        try {
            Utils.hideInputKeyboard(this, verifyCodeView);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
